<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;系统管理&gt;基础信息管理&gt;我的快捷方式</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
			<button type="button" class="btn dpbtn_red" onclick="del();">删除</button>
		</div>
		
		<div class="ibox-content">
			<div role="form" class="form-inline">
				<div class="form-group">
					<input type="text" placeholder="请输入快捷菜单名称" id="shortcutName"
						name="shortcutName" class="form-control">
				</div>
				<button class="zhixcx" type="button" onclick="query();">执行查询</button>
			</div>
		</div>
		<div class="ibox-content">
			<span class="warning-label">注：相应主页最多显示按序号的前18个快捷方式</span>
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>


	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>
	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>

	<script type="text/javascript">
    var serviceName = "快捷方式";
    var addUrl = 'shortcutAdd.jsp';
    var delUrl = '${basePath}/BaseShortcutController/remove';
    var listUrl = '${basePath}/BaseShortcutController/shorcutList';

    //新增
    var add = function () {
    	var rowNum = jQuery("#table_list_1").jqGrid('getGridParam', 'records');
    	/* if(rowNum>8){
    		layer.msg("快捷方式已超8条，请删除后再增加！", {icon: 5});
    		return;
    	} */
        var url = addUrl;
        baseAdd.call(this, serviceName, url);
    }

    //删除
    var del = function () {
        var url = delUrl;
        baseDel.call(this, serviceName, url);
    }
	
    //修改
    
    var update = function () {
        var url = listUrl;
        baseUpdate.call(this, serviceName, url);
    }
    
    //条件搜索
    var query = function () {
        var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
        var shortcutName = document.getElementById('shortcutName').value || '';
        $.extend(postData, {shortcutName: shortcutName.trim()});
        refresh();
    }
	
    var updateLayer;
    var getData = function () {
   		winWidth = $(window).width();
   	    winHeight = document.body.offsetHeight - 400;
	    var win = winWidth / 4 - 20;
        $.jgrid.defaults.styleUI = 'Bootstrap';
        jQuery("#table_list_1").jqGrid
        ({
            url: listUrl,
            datatype: "json",
            colNames: ['主键','快捷方式名称', '排序','菜单ID'],
            colModel: [
				{name: 'replaceId', index: 'BS.id', hidden:true},
                {name: 'shortcutName', index: 'BS.shortcutName', width: win, align: "center"},
                {name: 'sortValue', index: 'BS.sortValue', width: win, align: "center"},
                {name: 'powerId', index: 'BS.powerId', hidden:true},
            ],
            mtype: "post",
            height: winHeight,
            width:winWidth,  
            autowidth: true,
            shrinkToFit: true,
            sortorder : "asc",
            sortname : 'BS.sortValue',
            viewrecords: true,
            pager: "#pager_list_1",
            hidegrid: false,
            multiselect: true,
            altRows:true,
            altclass:'someClass',
            ondblClickRow:function(rowId,v,e)
            {		
	          	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
	          	  var id = rowData.replaceId;
	          	  var powerId = rowData.powerId;
	          	  updateLayer =  layer.open({
	  		    	  type: 2,
	  		    	  title: '修改快捷方式',
	  		    	  shadeClose: true,
	  		    	  shade: 0.8,
	  		    	  area: ['500px', '60%'],
	  		    	  content: 'shortcutUpdate.jsp?id='+id+"&powerId="+powerId,
	  		    	  end: function () {
	  		    		  refresh();
	  		          }
	  	    	});
            },
            jsonReader: {
                root: "result.rows",
                page: "result.page",
                total: "result.total",
                records: "result.records",
                repeatitems: false,
                id: "replaceId"
            },
            loadComplete:function(datas){
          	  if (datas.flag == "100100") {
                    layer.msg("查询成功!", {icon: 6, time: 1000});
                    return;
                }
          	  if(datas.flag == '100802') {
  				  top.location.href = thisLoginUrl;
  				  return;
  			  }

          	  layer.msg(datas.message, {icon: 2});
            }
        });
    }

    var winWidth = $(window).width();
    var winHeight = $(window).height();

    jQuery(function ($) {
        getData();
    });

    window.onresize = function () {
        $("#table_list_1").setGridWidth($(window).width() - 80);
    }
	
    var addlayer;
    var baseAdd = function (serviceName, url) {
    	addlayer=layer.open({
            type: 2,
            title: '添加' + serviceName,
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '60%'],
            content: url,
            end: function () {
                refresh();
            }
        });
    }

    var baseDel = function (serviceName, url) {
        var id = $('#table_list_1').jqGrid('getGridParam', 'selarrrow').join(",");
        if (id == "" || null == id) {
            layer.msg("请选择要删除的" + serviceName + "!", {icon: 5});
            return;
        }
        
        var data = $('#commentForm').serialize();
		layer.confirm('您确认要修改吗？', {
  			  btn: ['确定','取消'] //按钮
		},function(){
			layer.closeAll();
        $.dpAjax({
            url: url,
            data: {
                "id": id
            },
            success: function (datas) {
                if (datas.flag == "100100") {
                    layer.msg("删除执行成功！", {icon: 6});
                    refresh();
                    return;
                }
                if (datas.flag == "100200") {
                    $.fn.showDatas({"datas": datas});
                    return;
                }
                layer.msg(datas.message, {icon: 2});
              }
           })  
        });
    }
	
    var refresh = function () {
        $("#table_list_1").jqGrid("setGridParam", {search: true}).trigger("reloadGrid", [{page: 1}]);
    }
</script>
</body>
</html>
